package top.burning.confidant.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import top.burning.confidant.enums.MsgEnum;
import top.burning.confidant.model.pojo.Book;
import top.burning.confidant.model.result.Result;
import top.burning.confidant.service.BookService;

import java.util.UUID;

@RestController
public class BookController {
    @Autowired
    private BookService bookService;
    @PostMapping(value = "/user/addBook")
    @ResponseBody
    public  Result addBook(@RequestBody(required = false)  Book books){
        Result result;
        String s = UUID.randomUUID().toString();


        Book book=new Book();
        book.setAuthor("22");
        book.setBookId(Integer.valueOf(s.replaceAll("[a-z|-]", "").substring(0, 9)));
        book.setBookName("jvm");
        book.setbPicture("2312.321");
        book.setbUserId(23423);
        book.setPrice(555.54);
        book.setNewOld(6);
        book.setTheme("5678");
        book.setStyle("555");
        book.setCountry("zhongguo");
        book.setRemark("dhas all asbc bfc haokacb a ");
        book.setPress("sasd");
        book.setDescri("this is my book");
        if (bookService.addBook(book)==-1){
           result= Result.error(MsgEnum.NOT_FIND_DATA);
        }
        else {
            result= Result.success();
        }
        return result;
    }
}